﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BankingApp.Models;
using BankingApp.Data;
using BankingApp.Data.Models;

namespace BankingApp.Adapters
{
    public class AccountAdapter : IBankingAdapter
    {
        public List<UserAccountViewModel> GetAccount(string userId)
        {
            List<UserAccountViewModel> models = null;
            using (BankingDbContext db = new BankingDbContext())
            {
                models = db.UserAccount.Where(m => m.UserLoginId == userId)
                    .Select(m => new UserAccountViewModel
                    {
                        AccountNumber = m.AccountNumber,
                        Name = m.Name,
                        BankBalance = m.Balance,
                        LogInDate = m.LogInDate,
                        UserLoginId = m.UserLoginId

                        
                    }).ToList();
            }
            return models;
        }

        public void CreateAccount(UserAccountViewModel model, string userId)
        {
            using (BankingDbContext db = new BankingDbContext())
            {
                UserAccount dbAccounts = new UserAccount
                {
                    AccountNumber = model.AccountNumber,
                    Balance = model.BankBalance,
                    Name = model.Name,
                    LogInDate = model.LogInDate,
                };
                db.UserAccount.Add(dbAccounts);
                db.SaveChanges();
            }
        }
    }
}